<?php

// Store类
class StoreAction extends Action {
	
	
	
	public function addStoreDistrictValue($parentId,$name,$districtCategoryId){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		$StoreDistrictModel = M("store_district");
		$condition['parentId'] = array('eq',$parentId);
		$condition['deleted'] = array('eq',0);
		$condition['fromCustomerId'] = array('eq',$customerId);
		$condition['districtCategoryId'] = array('eq',$districtCategoryId);
		$maxCode = $StoreDistrictModel->where($condition)->max('code');
		$code = null;
		if($maxCode){
			//已经存在同级区域或店铺信息
			$preCode = substr($maxCode,0,strlen($maxCode)-4);
			$lasCode = substr($maxCode,strlen($maxCode)-4,4);
			$code = $preCode.((int)$lasCode+1);
			
		}else{
			//新一级首个区域或店铺信息
			$pCondition['id'] = array('eq',$parentId);
			$pCondition['deleted'] = array('eq',0);
			$pCondition['fromCustomerId'] = array('eq',$customerId);
			$pCondition['districtCategoryId'] = array('eq',$districtCategoryId);
			//更改父的hasChild
			$StoreDistrictModel->where($pCondition)->setField("leaf", 0);
			
			$parent = $StoreDistrictModel->where($pCondition)->find();
			if($parent['code']){
				$code = $parent['code'].'1000';
			}else{
				$code = '1000';
			}
			
		}
		$data["parentId"] = $parentId;
		$data["name"] = $name;
		$data["code"] = $code;
		$data["fromCustomerId"] = $customerId;
		$data['districtCategoryId'] = $districtCategoryId;
		
		$data["updateTime"] = date("Y-m-d H:i:s");
		$result = $StoreDistrictModel->add($data);
		
		Session::switchCustomer($customerId);
		if(!$result){
			Output::instance()->resultCode(code_sql_error);
			return;
		} 
		return $result;
	}
	
	public function addStoreDistrict($parentId,$name,$districtCategoryId){
		$result = $this->addStoreDistrictValue($parentId, $name, $districtCategoryId);
		if(!$result){
			return;
		}
		$data["id"] = $result;
		Output::instance()->object($data);
	}
	
	
	public function updateStoreDistrict($id,$name){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		
		$StoreDistrictModel = M("store_district");
		$condition['id'] = array('eq',$id);
		//$condition['deleted'] = array('eq',0);
		$data["name"] = $name;
		$data["updateTime"] = date("Y-m-d H:i:s");
		$result = $StoreDistrictModel->where($condition)->save($data);
		
		Session::switchCustomer($customerId);
		if($result !== false){
			Output::instance()->resultCode(code_success);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
		
	}
	
	public function deleteStoreDistrict($id){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		$StoreDistrictModel = M("store_district");
// 		$condition['id'] = array('eq',$id);
		$StoreModel = M("store");
		$StoreModel->where("districtId=$id")->setField("deleted", 1);
		$result = $StoreDistrictModel->where("id=$id")->setField("deleted", 1);
		
		if($result){
			$storeDistrict = $StoreDistrictModel->where("id=$id")->find();
			
			$parentId = $storeDistrict['parentId'];
			
			$condition['deleted'] = array('eq',0);
			$condition['parentId'] = array('eq',$parentId);
			$count = $StoreDistrictModel->where($condition)->count();
			if($count == 0){
				$StoreDistrictModel->where("id=$parentId")->setField("leaf", 1);
				//通知后台更新叶子
				Session::switchCustomer($customerId);
				Output::instance()->resultCode(code_store_district_not_exist);
				return;
			}
			Session::switchCustomer($customerId);
			Output::instance()->resultCode(code_success);
		}else{
			Session::switchCustomer($customerId);
			Output::instance()->resultCode(code_sql_error);
		}
		
	}
	
// 	public function getStoreDistrictList($parentId,$order="id", $orderBy="asc", $start=0, $limit=25){
		
// 		$retVal = Session::init();
// 		if (!$retVal) {
// 			Output::instance()->resultCode(code_access_denied);
// 			return;
// 		}
// 		$StoreDistrictModel = M("store_district");
// 		$condition['parentId'] = array('eq',$parentId);
// 		$condition['deleted'] = array('eq',0);
		
// 		$arr = $StoreDistrictModel->where($condition)->order("$order $orderBy")->limit("$start,$limit")->select();
// 		if($arr){
// 			Output::instance()->objArray($arr, $StoreDistrictModel->where($condition)->count());
// 		} else {
// 			Output::instance()->resultCode(code_success);
// 		}
// 	}
	public function getList($method,$districtCategoryId,$id,$order="CONVERT( name USING gbk )",$orderBy="asc",$start = 0, $limit =25){
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}

		$module = 'store';
		$params = new stdClass();
		$params->districtCategoryId = $districtCategoryId;
		$params->id = $id;
		$params->start = $start;
		$params->limit = $limit;
		$params->order = $order;
		$params->orderBy = $orderBy;
		
		Module::callModule($module, Session::$user, $method, $params);
	}
	
	public function getStoreById($id){
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$StoreModel = M("store");

		$serviceList = M("store_service_list");
// 		$condition['store.deleted'] = array('eq',0);
// 		$condition['id'] = array('eq',$id);

// 		$store =  $StoreModel->where($condition)->find();
		
		$condition["store.id"] = array('eq',$id);
// 		$condition["store.districtId"] = array('eq',$districtId);
		$condition["store.deleted"] = array('eq',0);
		
		$store = $StoreModel->alias('store')
		->join("LEFT JOIN wx_store_district district on store.districtId = district.id and district.deleted=0")
		->join("LEFT JOIN wx_store_district_category category on category.id = district.districtCategoryId and category.deleted=0")
		->join("wx_mivendor vendor on store.vId=vendor.id")
		->where($condition)
		->field("store.*,district.name as districtName,
				district.id as districtId,district.leaf as districtLeaf,
				category.id as categoryId,category.name as categoryName,category.typeId,vendor.id as vendorId,vendor.name as vendorName")
		->find();
		if($store){
			$store['picUrl1']=json_decode($store['picUrl1'],true);
			$serviceInfo = $serviceList->where("cid=$customerId and storeId=$id")->field("group_concat(serviceId) as storeService")->find();
			$store['storeService']=$serviceInfo['storeService'];
			Output::instance()->object($store);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
		
	}
	
	public function getRootDistrict($districtCategoryId){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		$StoreDistrictModel = M("store_district");
		$condition['parentId'] = array('exp','is NULL');
		$condition['deleted'] = array('eq','0');
        $condition['fromCustomerId'] = array('eq',$customerId);
		$condition['districtCategoryId'] = array('eq',$districtCategoryId);

		$result = $StoreDistrictModel->where($condition)->find();
		if($result){
			Session::switchCustomer($customerId);
			
			Output::instance()->object($result);
		} else {
			$data["name"] = '门店信息';
			$data["updateTime"] = date("Y-m-d H:i:s");
			$data['fromCustomerId']=$customerId;
			$data["districtCategoryId"] = $districtCategoryId;
			$result = $StoreDistrictModel->add($data);
			
			Session::switchCustomer($customerId);
			
			if($result){
				$res = new stdClass();
				$res->id = $result;
				$res->name = $data["name"];
				$res->leaf = 1;
				Output::instance()->object($res);
			}else{
				Output::instance()->resultCode(code_sql_error);
			}
		}
		
	}

    /**
     * @param $districtId
     * @param $name
     * @param $phone
     * @param $contact
     * @param $address
     * @param $picUrl
     * @param $url
     * @param $longitude
     * @param $latitude
     * @param $type
     * @param $serialNumber
     * @param $isPickUp
     * @param $accessTag
     * @param $tplId
     * @param $vendorId
     * @param $province
     * @param $city
     * @param $area
     * @param $town    乡镇
     * @return mixed|void
     */
	public function  addStoreValue($districtId,$name,$phone,$contact,$address,$picUrl,$url,$longitude,$latitude,$type
			,$serialNumber,$isPickUp,$accessTag,$tplId,$vendorId,$province,$city,$area,$town){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		$StoreModel = M("store");
		$data["districtId"] = $districtId;
		$data["vId"] = $vendorId;
		$data["name"] = $name;
		$data["phone"] = $phone;
		$data["contact"] = $contact;
		$data["address"] = $address;
		$data["picUrl1"] = $picUrl;
		$picUrl = json_decode($picUrl,true);
		$data["picUrl"] = $picUrl[0]['picUrl'];
		$data["customerId"] = $customerId;
		$data["url"] = $url;
		$data["longitude"] = $longitude;
		$data["latitude"] = $latitude;
		$data["type"] = $type;
		$data["province"] = $province;
		$data["city"] = $city;
		$data["country"] = $area;
		$data["town"] = $town;//增加乡镇信息保存
		$data["accessTag"] = $accessTag;
		//李建蓉为门店支持模板添加
		$data["tplId"]=$tplId;
		if($serialNumber == null){
			$data["serialNumber"] = NULL;
		}else{
			$data["serialNumber"] = $serialNumber;
				
		}
		$data["isPickUp"] = $isPickUp;
		$data["updateTime"] = date("Y-m-d H:i:s");
		
		$result = $StoreModel->add($data);
		
		Session::switchCustomer($customerId);
		if(!$result){
			Output::instance()->resultCode(code_sql_error);
			return;
		}
		return $result;
	}


	public function  addStore($districtId,$name,$phone,$contact,$address,$picUrl,$longitude,$latitude
			,$serialNumber,$isPickUp,$province=null,$type=null,$city=null,$area=null,$accessTag = NULL,$tplId='store_detail',$vendorId=null,$storeService=null,$url=null,$town=null){
		$result = $this->addStoreValue($districtId, $name, $phone, $contact, $address, $picUrl, $url, $longitude,
			$latitude, $type, $serialNumber, $isPickUp, $accessTag,$tplId,$vendorId,$province,$city,$area,$town);

		if(!$result){
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$StoreModel = M("store");
		$serviceList = M("store_service_list");
		Session::switchCustomer($customerId);
		if($storeService){
			$serviceList->where("cid=$customerId and storeId=$result")->delete();
			$storeService = explode(",",$storeService);
			foreach($storeService as $key=>$value){
				$data[$key]['cid']=$customerId;
				$data[$key]['storeId']=$result;
				$data[$key]['serviceId']=$value;
			}
			$serviceList->addAll($data);
		}
		$condition["id"] =  array('eq',$result);
		$reslult = $StoreModel->where($condition)->find();

		Output::instance()->object($reslult);

        R('Log/add', array('storeManage', '', '门店管理', op_add, '', '添加门店：' . $name));
	}
	
	public function updateStore($id,$districtId,$name,$phone,$contact=NULL,$address,$picUrl,$longitude,$latitude
			,$serialNumber=NULL,$isPickUp,$accessTag=NULL,$tplId='store_detail',$type=null
			,$onlineReserve=false,$reserveWebPageId=NULL,$reserveWebPageName=NULL,$email=NULL,$feyinDeviceNo=NULL,$onlineOrder=false
			,$breakfastTime=NULL,$lunchTime=NULL,$dinnerTime=NULL,$vendorId=null,$storeService=null,$url=null,$province,$city,$area=NULL){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$serviceList = M("store_service_list");
		$StoreModel = M("store");
		$condition['id'] = array('eq',$id);
		$data['vId']=$vendorId;
		$data["districtId"] = $districtId;
		$data["name"] = $name;
		$data["phone"] = $phone;
		$data["contact"] = $contact;
		$data["address"] = $address;
		$data["picUrl1"] = $picUrl;
		$picUrl = json_decode($picUrl,true);
		$data["picUrl"] = $picUrl[0]['picUrl'];
		$data["url"] = $url;
		$data["longitude"] = $longitude;
		$data["latitude"] = $latitude;
		$data["type"] = $type;
		$data["accessTag"] = $accessTag;
		$data["tplId"]=$tplId;
		$data["province"] = $province;
		$data["city"] = $city;
		$data["country"] = $area;
		if($serialNumber == null){
			$data["serialNumber"] = NULL;
		}else{
			$data["serialNumber"] = $serialNumber;
			
		}
		$data["isPickUp"] = $isPickUp;
		$data["updateTime"] = date("Y-m-d H:i:s");
		$result = $StoreModel->where($condition)->save($data);
        $sql = $StoreModel->getLastSql();
		if($storeService){
			$serviceList->where("cid=$customerId and storeId=$id")->delete();
			$storeService = explode(",",$storeService);
			foreach($storeService as $key=>$value){
				$serviceData[$key]['cid']=$customerId;
				$serviceData[$key]['storeId']=$id;
				$serviceData[$key]['serviceId']=$value;
			}
			$serviceList->addAll($serviceData);
		}
		Session::switchCustomer($customerId);
		
		if($result !== false){
	 		$data["id"] = $id;
	 		$reslult = $StoreModel->where($condition)->find();
			Output::instance()->object($reslult);

            R('Log/add', array('storeManage', '', '门店管理', op_add, $sql, '修改门店：' . $name));
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	public function getStoreExtendDishByStoreId($storeId){
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		$StoreExtendBaseModel = M("store_extend_base");
		$StoreExtendDishModel = M("store_extend_dish");
		$condition['storeId'] = array('eq',$storeId);
		
		$storeExtend = $StoreExtendBaseModel->where($condition)->find();
		$storeExtendDish = $StoreExtendDishModel->where($condition)->find();
		
		if($storeExtend){
			if($storeExtendDish){
				$storeExtend['breakfastTime'] =$storeExtendDish['breakfastTime'];
				$storeExtend["lunchTime"] = $storeExtendDish["lunchTime"];
				$storeExtend["dinnerTime"] = $storeExtendDish["dinnerTime"];
			}else{
				$storeExtend['breakfastTime'] =NULL;
				$storeExtend["lunchTime"] = NULL;
				$storeExtend["dinnerTime"] = NULL;
			}
			
			
			Output::instance()->object($storeExtend);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
		
	}
	public function updateStoreExtendBaseByReserve($storeId,$onlineReserve=false,$reserveWebPageId=NULL,$reserveWebPageName=NULL,
			$email=NULL,$emailNoticeFormat=NULL,
			$feyinDeviceNo=NULL,$feyinPrintFormat=NULL,
			$feyinDeviceNoCustom = NULL, $feyinPrintFormatCustom = NULL,
			$onlineOrder=false, $breakfastTime=NULL,$lunchTime=NULL,$dinnerTime=NULL, $onlineTakeout=false){
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		$StoreExtendBaseModel = M("store_extend_base");
		$StoreExtendDishModel = M("store_extend_dish");
		
		$condition['storeId'] = array('eq',$storeId);
		
		$storeExtend = $StoreExtendBaseModel->where($condition)->find();
		
		$storeExtendDish = $StoreExtendDishModel->where($condition)->find();
		
		$data["storeId"] = $storeId;
		$data["updateTime"] = date("Y-m-d H:i:s");
		
		$data["onlineReserve"] = $onlineReserve === 'true'? true: false;
		if($reserveWebPageId == ''){
			$reserveWebPageId = NULL;
		}
		if($reserveWebPageName == ''){
			$reserveWebPageName = NULL;
		}
		if($email == ''){
			$email = NULL;
		}
		$data["reserveWebPageId"] = $reserveWebPageId;
		$data["reserveWebPageName"] = $reserveWebPageName;
		
		$data["email"] = $email;
		$data["emailNoticeFormat"] = $emailNoticeFormat;
		$data["feyinDeviceNo"] = $feyinDeviceNo;
		$data["feyinPrintFormat"] = $feyinPrintFormat;
		$data["feyinDeviceNoCustom"] = $feyinDeviceNoCustom;
		$data["feyinPrintFormatCustom"] = $feyinPrintFormatCustom;
		
		$data["onlineOrder"] = $onlineOrder === 'true'? true: false;
		$data["onlineTakeout"] = $onlineTakeout === 'true'? true: false;
		
		if($breakfastTime ==''){
			$breakfastTime = NULL;
		}
		if($lunchTime ==''){
			$lunchTime = NULL;
		}
		if($dinnerTime ==''){
			$dinnerTime = NULL;
		}
		
		$dataDish["breakfastTime"] = $breakfastTime;
		$dataDish["lunchTime"] = $lunchTime;
		$dataDish["dinnerTime"] = $dinnerTime;
		$dataDish["storeId"] = $storeId;
		
		if($storeExtend){
			$result = $StoreExtendBaseModel->where($condition)->save($data);
		}else{
			$result = $StoreExtendBaseModel->add($data);
		}
	
		if($storeExtendDish){
			$resultDish = $StoreExtendDishModel->where($condition)->save($dataDish);
		}else{
			$resultDish = $StoreExtendDishModel->add($dataDish);
		}
	
		Session::switchCustomer($customerId);
		
		if($result !== false && $resultDish !== false){
	 		$data["storeId"] = $storeId;
	 		$data["breakfastTime"] = $breakfastTime;
	 		$data["lunchTime"] = $lunchTime;
	 		$data["dinnerTime"] = $dinnerTime;
	 		
			Output::instance()->object($data);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	
	
	public function deleteStore($id){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
	
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		
		$StoreModel = M("store");
		$condition['id'] = array('eq',$id);
		$result = $StoreModel->where($condition)->setField("deleted", 1);
		$sql = $StoreModel->getLastSql();
		$name = $StoreModel->where($condition)->getField('name');
	
		$StoreExtendBaseModel = M("store_extend_base");
		$StoreExtendDishModel = M("store_extend_dish");
		
		$conditionExtend['storeId'] = array('eq',$id);
		
		if($result){
			$StoreExtendBaseModel->where($conditionExtend)->delete();
			$StoreExtendDishModel->where($conditionExtend)->delete();
			
			Session::switchCustomer($customerId);
            R('Log/add', array('storeManage', '', '门店管理', op_delete, $sql, '删除门店：' . $name));
			Output::instance()->resultCode(code_success);
		}else{
			Session::switchCustomer($customerId);
			Output::instance()->resultCode(code_sql_error);
		}
	
	}
	
// 	public function getStoreList($districId,$order="id", $orderBy="asc", $start=0, $limit=25){
		
// 		$retVal = Session::init();
// 		if (!$retVal) {
// 			Output::instance()->resultCode(code_access_denied);
// 			return;
// 		}
// 		$StoreModel = M("store");
// 		$condition['districtId'] = array('eq',$districId);
// 		$condition['deleted'] = array('eq',0);
		
// 		$arr = $StoreModel->where($condition)->order("$order $orderBy")->limit("$start,$limit")->select();
// 		if($arr){
// 			Output::instance()->objArray($arr, $StoreModel->where($condition)->count());
// 		} else {
// 			Output::instance()->resultCode(code_success);
// 		}
// 	}
	
	public function getStoreResourceDishList($storeId,$order="id", $orderBy="asc", $start=0, $limit=25){
				
		$StoreResourceBaseModel = M("store_resource_base");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$condition['storeId'] = array('eq',$storeId);
		$condition['deleted'] = array('eq',0);

// 		$arr = $StoreResourceBaseModel->where($condition)->order("$order $orderBy")->limit("$start,$limit")->select();
		
		$arr = $StoreResourceBaseModel->alias("base")->where($condition)->order("$order $orderBy")->limit("$start,$limit")
		->join('wx_store_resource_dish dish ON base.id=dish.storeResourceBaseId')->field("base.*,dish.minSize,dish.maxSize")->select();
		
		$count = $StoreResourceBaseModel->alias("base")->where($condition)
		->join('wx_store_resource_dish dish ON base.id=dish.storeResourceBaseId')->count();
		
		if($arr){
			Output::instance()->objArray($arr, $count);
		} else {
			Output::instance()->resultCode(code_success);
		}
		
	}
	
	
	public function addStoreResourceDish($storeId,$name,$minSize,$maxSize=NULL,$remark=NULL,$url=NULL){
		$StoreResourceBaseModel = M("store_resource_base");
		$StoreResourceDishModel = M("store_resource_dish");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$data["storeId"] = $storeId;
		$data["name"] = $name;
		
		$data["remark"] = $remark;
		$data["url"] = $url;
		
		$result = $StoreResourceBaseModel->add($data);
		
		if($result){
			$data["id"] = $result;
			
			$dataDish["minSize"] = $minSize;
			if($maxSize == 0){
				$maxSize = NULL;
			}
			$dataDish["maxSize"] = $maxSize;
			$dataDish["storeResourceBaseId"] = $result;
			
			$StoreResourceDishModel->add($dataDish);
			
			$data["minSize"] = $minSize;
			$data["maxSize"] = $maxSize;
			
			Output::instance()->object($data);
		} else {
			Output::instance()->resultCode(code_sql_error);
		}
	}
	public function updateStoreResourceDish($id,$storeId,$name,$minSize,$maxSize,$remark,$url){
		$StoreResourceModel = M("store_resource_base");
		$StoreResourceDishModel = M("store_resource_dish");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$condition['id'] = array('eq',$id);
		
		$data["storeId"] = $storeId;
		$data["name"] = $name;
		
		$data["remark"] = $remark;
		$data["url"] = $url;
		
		$result = $StoreResourceModel->where($condition)->save($data);
		
		$dataDish["minSize"] = $minSize;
		if($maxSize == 0){
			$maxSize = NULL;
		}
		$dataDish["maxSize"] = $maxSize;
		$conditionDish["storeResourceBaseId"] = array('eq',$id); 
		$resultDish = $StoreResourceDishModel->where($conditionDish)->save($dataDish);
	
		if($result !== false &&  $resultDish !== false){
			//
	 		$data["id"] = $id;
	 		
	 		$data["minSize"] = $minSize;
	 		$data["maxSize"] = $maxSize;
	 		
			Output::instance()->object($data);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	
	public function deleteStoreResourceDishById($id){
		$StoreResourceModel = M("store_resource_base");
		$StoreResourceDishModel = M("store_resource_dish");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
	
		$condition['id'] = array('eq',$id);
		$result = $StoreResourceModel->where($condition)->setField("deleted", 1);
		
		$conditionDish['storeResourceBaseId'] = array('eq',$id);
		$StoreResourceDishModel->where($conditionDish)->delete();
	
		if($result){
			Output::instance()->resultCode(code_success);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	public function deleteStoreResourceDishByStoreId($storeid){
		$StoreResourceModel = M("store_resource_base");
		$StoreResourceDishModel = M("store_resource_dish");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
	
		$condition['storeId'] = array('eq',$storeid);
		$result = $StoreResourceModel->where($condition)->setField("deleted", 1);
		
		if($result){
			
			$ids = $StoreResourceModel->where($condition)->field('id')->select();
			if($ids){
				$storeResourceBaseIds = array();
				foreach ($ids as $stdId){
					array_push($storeResourceBaseIds,$stdId['id']);
				}
				$rc['id'] = array('in',$storeResourceBaseIds);
			}
			
			$StoreResourceDishModel->where($rc)->delete();
			
			Output::instance()->resultCode(code_success);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	public function getStoreCategoryList($order="id", $orderBy="asc", $start=0, $limit=25, $search = ''){
		$StoreDistrictCategoryModel = M("store_district_category");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$customerId = Session::$user["customerId"];

		if ($search) {
            $condition['storeCategory.name'] = array('like','%' . $search . '%');
        }
		$condition['storeCategory.fromCustomerId'] = array('eq',$customerId);
		$condition['storeCategory.deleted'] = array('eq',0);
		$condition['ptype.dependence'] = array('eq','store');
		
		$arr = $StoreDistrictCategoryModel->alias("storeCategory")
		->where($condition)
		->order("$order $orderBy")->limit("$start,$limit")
		->join('wx_module_type ptype ON storeCategory.typeId=ptype.id')
		->field("storeCategory.*,ptype.name typeName")
		->select();
// 		$arr = $StoreDistrictCategoryModel->where($condition)->order("$order $orderBy")->limit("$start,$limit")->select();
		if($arr){
			$count = $StoreDistrictCategoryModel->alias("storeCategory")->where($condition)
			->join('wx_module_type ptype ON storeCategory.typeId=ptype.id')->count();
			Output::instance()->objArray($arr,$count);
		} else {
			Output::instance()->resultCode(code_success);
		}
	}
	public function getStoreCategoryById($id){
		$StoreDistrictCategoryModel = M("store_district_category");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$customerId = Session::$user["customerId"];
		
		$condition['storeCategory.id'] =  array('eq',$id);
		$condition['storeCategory.fromCustomerId'] = array('eq',$customerId);
		$condition['storeCategory.deleted'] = array('eq',0);
		$condition['ptype.dependence'] = array('eq','store');
		
		
		
		$category = $StoreDistrictCategoryModel->alias("storeCategory")
		->where($condition)
		->join('wx_module_type ptype ON storeCategory.typeId=ptype.id')
		->field("storeCategory.*,ptype.name typeName")->find();
		
// 		$arr = $StoreDistrictCategoryModel->where($condition)->order("$order $orderBy")->limit("$start,$limit")->select();
		if($category){
			Output::instance()->object($category);
		} else {
			Output::instance()->resultCode(code_success);
		}
	}
	
	
	public function addStoreCategory($typeId,$name){
		$StoreDistrictCategoryModel = M("store_district_category");
	
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		
		$data["typeId"] = $typeId;
		$data["name"] = $name;
		$data["fromCustomerId"] = $customerId;
		$data["updateTime"] = date("Y-m-d H:i:s");
		
		$result = $StoreDistrictCategoryModel->add($data);

		if($result){
			$data["id"] = $result;
			Output::instance()->object($data);
		} else {
			Output::instance()->resultCode(code_sql_error);
		}
	}
	public function updateStoreCategory($id,$typeId,$name){
		$StoreDistrictCategoryModel = M("store_district_category");
	
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
	
		$condition['id'] = array('eq',$id);
	
		$customerId = Session::$user["customerId"];
		
		$data["typeId"] = $typeId;
		$data["name"] = $name;
		$data["fromCustomerId"] = $customerId;
		$data["updateTime"] = date("Y-m-d H:i:s");
	
		$result = $StoreDistrictCategoryModel->where($condition)->save($data);
	
		if($result !== false){
			$data["id"] = $id;
			Output::instance()->object($data);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	
	public function deleteStoreCategoryById($id){
		$StoreDistrictCategoryModel = M("store_district_category");
	
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
	
		$condition['id'] = array('eq',$id);
		$result = $StoreDistrictCategoryModel->where($condition)->setField("deleted", 1);
	
		if($result){
			Output::instance()->resultCode(code_success);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
	}
	
	public function addStoreProductCategory($storeId,$categoryId, $type){
		$StoreProductCategoryModel = M("store_product_category");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$data['storeId'] = $storeId;
		$data['categoryId'] = $categoryId;
		$data['type'] = $type;
		$result = $StoreProductCategoryModel->add($data);
		
		if($result){
			$data["id"] = $result;
			Output::instance()->object($data);
		}else{
			Output::instance()->resultCode(code_sql_add_repeat);
		}
	}
	
	public function getStoreProductCategoryList($storeId, $type){
		$StoreProductCategoryModel = M("store_product_category");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$where["store.storeId"] = $storeId;
		$where["store.type"] = $type;
		$arr = $StoreProductCategoryModel->alias("store")->where($where)
		->join("wx_product_category category ON store.categoryId=category.id")
		->field("store.*,category.name")->select();
		
		
		if($arr){
			$count = $StoreProductCategoryModel->alias("store")->where($where)
			->join("wx_product_category category ON store.categoryId=category.id")
			->count();
			
			Output::instance()->objArray($arr,$count);
		}else{
			Output::instance()->resultCode(code_success);
		}
	}
	
	public function deleteStoreProductCategoryById($id){
		$StoreProductCategoryModel = M("store_product_category");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$condition['id'] = $id;
		$result = $StoreProductCategoryModel->where($condition)->delete();
		Output::instance()->resultCode(code_success);
	}
	public function deleteStoreProductCategoryByCategoryId($categoryId){
		$StoreProductCategoryModel = M("store_product_category");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$condition['categoryId'] = array('eq',$categoryId);
		$result = $StoreProductCategoryModel->where($condition)->delete();
		Output::instance()->resultCode(code_success);
	}
	public function deleteStoreProductCategoryByStoreId($storeId){
		$StoreProductCategoryModel = M("store_product_category");
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$condition['storeId'] = array('eq',$storeId);
		$result = $StoreProductCategoryModel->where($condition)->delete();
		Output::instance()->resultCode(code_success);
	}
	public function getStoreListByLocation($config,$lat,$lng,$minLat=null,$maxLat=null,$minLng=null,$maxLng=null,$order="id", $orderBy="asc", $start=0, $limit=5){
		$customerId = Session::$user['customerId'];
		Session::switchCustomer(0);
		$StoreModel = M("store");
		$isOpen=1;
		if($config!=false){
			$limit=$config['maxNum'];
			$isOpen=$config['isOpen'];
		}
		if($minLng == null || $maxLng== null || $minLat== null || $maxLat == null){
			$condition['store.longitude'] = array('gt',0);
			$condition['store.latitude'] = array('gt',0);
		}else{
			
			$condition['store.longitude'] = array('between',array($minLng,$maxLng));
			$condition['store.latitude'] = array('between',array($minLat,$maxLat));
		}
		$condition['store.deleted'] = array('eq',0);
		$condition['sd.deleted'] = array('eq',0);
		$condition['sdc.deleted'] = array('eq',0);
		$condition['sdc.fromCustomerId'] = array('eq',$customerId);
		$condition['ptype.dependence'] = array('eq','store');
		
		$storeList = $StoreModel->alias("store")
		->join("wx_store_district sd on sd.id = store.districtId")
		->join("wx_store_district_category sdc on sdc.id = sd.districtCategoryId")
		->join("LEFT JOIN wx_module_type ptype on ptype.id = sdc.typeId")
		->where($condition)
// 		->order("$order $orderBy")
		->order("dis asc")
		->limit("$start,$limit")
		->field("store.*,(abs(store.latitude-$lat) + abs(store.longitude-$lng)) dis")
		->select();
		Session::switchCustomer($customerId);
		if(isset($storeList) && $isOpen==1){
			$disStoreList = array();
			
			for ($i= 0;$i< count($storeList); $i++){
				
				$tlng = $storeList[$i]["longitude"];
				$tlat = $storeList[$i]["latitude"];
				
				$tDis = getDistance($tlat,$tlng,$lat,$lng);
				if($tlng== 0 && $tlat == 0){
					$tDis =$tDis+$i;
					$storeList[$i]["distance"] = null;
				}else{
					
					$storeList[$i]["distance"] = $tDis;
				}
				$disStoreList["$tDis"] = $storeList[$i];
			}
			
// 			print_r($disStoreList);
			//按照关键字升序
			ksort($disStoreList);
			Output::instance()->objArray($disStoreList);
			return $disStoreList;
		}else{
			return;
		}
		
		
	}
	
	/**
	 * 模糊查询门店列表
	 * @param string $districtCategoryId 类别id
	 * @param string $districtName 区域名称
	 * @param string $districtId 区域id
	 * @param string $storeId 门店id
	 * @param string $storeName 门店名称
	 * @param string $order 排序 门店名称降序
	 * @param string $orderBy
	 * @param number $start
	 * @param number $limit
	 */
	
	public function getStoreWildcardQueryList($vid=null,$districtCategoryId=NULL,$districtName=NULL,$districtId=NULL,$storeId=NULL,$storeName=NULL,$order="CONVERT( store.name USING gbk )",$orderBy="asc",$start = 0, $limit =25,$isExport=false){
		$StoreModel = M("store");
		$DistrictModel = M("store_district");
		$SqlModel = new Model();
		
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$customerId = Session::$user['customerId'];
		
		//SELECT * FROM `wx_store_district` WHERE  INSTR(LEFT(`code`,LENGTH('1000')),'1000')>0;
		
		$condition["store.deleted"] = array('eq',0);
		if($districtCategoryId != NULL && $districtCategoryId !=''){
			$condition["category.id"] = array('eq',$districtCategoryId);
		}
		
		if($storeId != NULL && $storeId!= ''){
			$condition["store.id"] = array('eq',$storeId);
		}
		
		if($storeName != NULL && $storeName != ''){
			$storeName = urldecode($storeName);
			$condition["store.name"] = array('like',"%$storeName%");
		}
		$disIds = '';
		if($districtId != NULL && $districtId != ''){
			$disCon["id"] = array('eq',$districtId);
			$dis = $DistrictModel->where($disCon)->find();
			if($dis){
				$code = $dis["code"];
				$disSql = "select group_concat(id) as ids from wx_store_district where INSTR(LEFT(code,LENGTH('$code')),'$code')>0 ";
				$disArr = $SqlModel->query($disSql);
				if($disArr){
					$disIds = $disArr[0]['ids'];
					if($disIds){
						$condition["district.id"] = array('exp'," in($disIds)");
					}else{
						Output::instance()->resultCode(code_success);
					}
				}
			}
		}
		
		if($districtName != NULL && $districtName != ''){
			$districtName = urldecode($districtName);
			
			$disCon["name"] = array('like',"%$districtName%");
			$disArr = $DistrictModel->where($disCon)->select();
			if($disArr){
				$disIds;
				foreach ($disArr as $dis){
					$code = $dis["code"];
						
					$disSql = "select group_concat(id) as ids from wx_store_district where INSTR(LEFT(code,LENGTH('$code')),'$code')>0 ";
					$disArr = $SqlModel->query($disSql);
					if($disArr){
						$disIdsTem = $disArr[0]['ids'];
						if($disIdsTem){
							if($disIds == ''){
								$disIds = $disIdsTem;
							}else{
								$disIdsTem = $disIds. ','.$disIdsTem;
							}
						}
					}
				}
		
				if($disIds){
					$condition["district.id"] = array('exp'," in($disIds)");
				}else{
					Output::instance()->resultCode(code_success);
				}
				// 				$condition["district.id"] = array('exp'," INSTR(LEFT(district.code,LENGTH('$code')),'$code')>0");
			}
		}

		$condition["store.customerId"] = array('eq',$customerId);
        $vid?$condition["store.vId"] = array('eq',$vid):"";
		if($isExport){
            $arr = $StoreModel->alias('store')
                ->join("LEFT JOIN wx_store_district district on store.districtId = district.id and district.deleted =0")
                ->join("LEFT JOIN wx_store_district_category category on category.id = district.districtCategoryId and category.deleted = 0 and category.fromCustomerId = $customerId")
                ->join("LEFT JOIN wx_module_type ptype on ptype.id = category.typeId and ptype.dependence='store'")
                ->join("wx_mivendor ven on store.vId=ven.id")
                ->where($condition)
                ->order("$order $orderBy")
                ->field("store.*,district.name as districtName,
				district.id as districtId,district.leaf as districtLeaf,
				category.id as categoryId,category.name as categoryName,category.typeId,ptype.name as tName,ven.name as vendorName")
                ->select();
		    foreach($arr as $key=>$value){
                $newArr[$key]['categoryName']=$value['categoryName'];
                $newArr[$key]['vendorName']=$value['vendorName'];
                $newArr[$key]['districtName']=$value['districtName'];
                $newArr[$key]['name']=$value['name'];
                $newArr[$key]['province']=$value['province'];
                $newArr[$key]['city']=$value['city'];
                $newArr[$key]['country']=$value['country'];
                $newArr[$key]['address']=$value['address'];
                $newArr[$key]['phone']=$value['phone'];
                $newArr[$key]['contact']=$value['contact'];
                $newArr[$key]['longitude']=$value['longitude'];
                $newArr[$key]['latitude']=$value['latitude'];
                if($value['isPickUp']){
                    $newArr[$key]['isPickUp']='是';
                }else{
                    $newArr[$key]['isPickUp']='否';
                }
            }

            $expCellName  = array(
                array('categoryName','门店分类'),
                array('vendorName','所属商家'),
                array('districtName','门店区域'),
                array('name','门店名称'),
                array('province','省'),
                array('city','市'),
                array('country','区'),
                array('address','地址'),
                array('phone','电话'),
                array('contact','联系人'),
                array('longitude','经度'),
                array('latitude','纬度'),
                array('isPickUp','支持自提')
            );
            Output::instance()->objArrayExcel('门店信息', $expCellName, $newArr);
        }else{
            $arr = $StoreModel->alias('store')
                ->join("LEFT JOIN wx_store_district district on store.districtId = district.id and district.deleted =0")
                ->join("LEFT JOIN wx_store_district_category category on category.id = district.districtCategoryId and category.deleted = 0 and category.fromCustomerId = $customerId")
                ->join("LEFT JOIN wx_module_type ptype on ptype.id = category.typeId and ptype.dependence='store'")
                ->join("wx_mivendor ven on store.vId=ven.id")
                ->where($condition)
                ->order("$order $orderBy")
                ->limit("$start,$limit")
                ->field("store.*,district.name as districtName,
				district.id as districtId,district.leaf as districtLeaf,
				category.id as categoryId,category.name as categoryName,category.typeId,ptype.name as tName,ven.name as vendorName")
                ->select();
            if($arr){
                $count = $StoreModel->alias('store')
                    ->join("LEFT JOIN wx_store_district district on store.districtId = district.id and district.deleted =0")
                    ->join("LEFT JOIN wx_store_district_category category on category.id = district.districtCategoryId and category.deleted = 0 and category.fromCustomerId = $customerId")
                    ->join("LEFT JOIN wx_module_type ptype on ptype.id = category.typeId and ptype.dependence='store'")
                    ->where($condition)->count();
                Output::instance()->objArray($arr, $count);
            } else {
                Output::instance()->resultCode(code_success);
            }
        }
	}
	/**
	 * 
	 * Enter 保存门店和商品标签的关联关系
	 * @param unknown_type $storeId
	 * @param unknown_type $tagsId
	 */
	public function updateStoreProductTags($storeId,$tagsId){	
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$StoreTagsModel = M("store_tags");	
		
		$arrTags = explode(',',$tagsId);
		$success = true;
		foreach ($arrTags as $tagId){
			$data['storeId']=$storeId;
			$data['productTagId']=$tagId;
			$data['fromCustormerId']=$customerId;
			//判断是否已经在列表中了，防止重复添加
			$conditon['storeId']=array('eq',$storeId);
			$conditon['productTagId']=array('eq',$tagId);
			$size=$StoreTagsModel->where($conditon)->find();
			if(count($size)<1){
				$success =$StoreTagsModel->add($data);
			}
		}
		Session::switchCustomer($customerId);
		if($success){
			Output::instance()->resultCode(code_success);
		}
	}
	/**
	 * 保存门店位置配置
	 * Enter description here ...
	 * @param unknown_type $isOpen
	 * @param unknown_type $maxNum
	 * @param unknown_type $customerId
	 */
	public  function saveStoreConfig($isOpen=1,$maxNum=4){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$StoreConfig = M("store_config");
		
		$condition['fromCustormerId'] = array('eq',$customerId);
		
		$result =$StoreConfig->where($condition)->find();
		$data["isOpen"]=$isOpen;
		$data["maxNum"]=$maxNum;
		if($result){
			$code=$StoreConfig->where($condition)->save($data);
		}else{
			$data["fromCustormerId"]=$customerId;
			$code=$StoreConfig->add($data);
		}
		Session::switchCustomer($customerId);
		if($code !== false){
			Output::instance()->resultCode(code_success);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
	}
	/***
	 * 根据商品标签删除商品和门店的关联关系
	 */
	public  function  deleteStorePruduct($storeId,$tagId){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$StoreTagsModel = M("store_tags");	
		$condition['storeId']=array('eq',$storeId);
		$condition['productTagId']=array('eq',$tagId);
		$condition['fromCustormerId']=array('eq',$customerId);
		$result=$StoreTagsModel->where($condition)->delete();
		if($result){
			Output::instance()->resultCode(code_success);
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
		Session::switchCustomer($customerId);
	}
	/**
	 *
	 * Enter 根据门店id获取门店内所属的商品
	 * @param unknown_type $storeId
	 */
	public function getProductByStoreId($storeId){
	    $retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
	    Session::switchCustomer(0);
	
	    $StoreTagsModel = M("store_tags");
	    $condition['storeId']=array('eq',$storeId);
	    $condition['fromCustormerId']=array('eq',$customerId);
	    $condition['c.deleted']=array('eq',0);
	    $condition['c.isRemoved']=array('eq',0);
	    $result=$StoreTagsModel->alias('a')
	    ->field('d.id as tagId,d.name as tagName,c.id as pid,c.name as proName,c.fixedPrice as price,a.storeId')
	    ->join('LEFT join wx_'. $customerId .'_module_product_tag_list as b on a.productTagId=b.tagId')
	    ->join('INNER join wx_'. $customerId .'_module_product as c on c.id=b.pid')
	    ->join('INNER join wx_'. $customerId .'_module_product_tag as d on d.id=b.tagId')
	    ->where($condition)
	    ->select();
	    Session::switchCustomer($customerId);
	    if ($result) {
	        Output::instance()->objArray($result);
	    } else {
	        Output::instance()->resultCode();
	    }
	}
	//门店服务项目
	public function getStoreService($name=null,$start=null,$limit=null){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$storeService = M("store_service");
		Session::switchCustomer($customerId);
		$where['cid']=array('eq',$customerId);
		$where['name']=array('like',"%$name%");
		if(isset($start)&&isset($limit)){
			$arr = $storeService->where($where)->limit($start,$limit)
				->field("id,name")->select();
		}else{
			$arr = $storeService->where($where)->field("name as tagName,id")->select();
		}
		$count = $storeService->where($where)->count();
		Output::instance()->objArray($arr,$count);

	}
	//获得服务项目
	public function getServiceInfo($id){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$storeService = M("store_service");
		Session::switchCustomer($customerId);
		$result = $storeService->where("id=$id")->find();
		Output::instance()->object($result);
	}

	//删除门店服务项目
	public function delStoreService($id){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$storeService = M("store_service");
		Session::switchCustomer($customerId);
		$result = $storeService->where("id=$id")->delete();
		if($result!==false){
			Output::instance()->resultCode();
		}else{
			Output::instance()->resultCode(code_sql_error);
		}

	}
	//增加门店服务项目
	public function addStoreService($name,$id=null){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$storeService = M("store_service");
		Session::switchCustomer($customerId);
		if($id){
			$where['id']=array("neq",$id);
		}
		$where['cid']=array('eq',$customerId);
		$where['name']=array("eq",$name);
		$serviceInfo = $storeService->where($where)->find();
		if($serviceInfo){
			Output::instance()->resultCode(1,"服务项目已存在!");
			return;
		}
		$data['name']=$name;
		if($id){
			$result = $storeService->where("id=$id")->save($data);
		}else{
			$data['cid']=$customerId;
			$result = $storeService->add($data);
		}
		if($result){
			Output::instance()->resultCode();
		}else{
			Output::instance()->resultCode(code_sql_error);
		}
	}
	/**
	 * 获取上次配置信息
	 * Enter description here ...
	 */
	public  function getStoreConfig(){
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		$customerId = Session::$user["customerId"];
		Session::switchCustomer(0);
		$StoreConfig = M("store_config");
		$condition['fromCustormerId'] = array('eq',$customerId);
		
		$result =$StoreConfig->where($condition)->find();
		if($result){
			Output::instance()->object($result);
		}else{
			Output::instance()->resultCode(code_success);
		}
		Session::switchCustomer($customerId);
	}

	public function getHomeUrl () {
        $retVal = Session::init();
        if (!$retVal) {
            Output::instance()->resultCode(code_access_denied);
            return;
        }
        $customerId = Session::$user["customerId"];
        $url = R('MiContent/getH5ServerHost');
        $url .= "call.html?customerId=".$customerId."&module=store&method=allStore";
        $return['code'] = 0;
        $return['msg'] = 'url返回';
        $return['data'] = $url;
        Output::instance()->object($return);

    }
}